package com.jzd1997;

/**
 * @author jiangzd
 * @date 2019-08-14 10:10
 * @email 39627020@qq.com
 */
public class Node{
    int data;
    Node next;

    Node(int data){
        this.data = data;
        this.next = null;
    }

    public void append(Node node){
        this.next = node;
    }

    public void show(){
        Node node = this;
        while(true){
            System.out.print(node.data + " ");
            node = node.next;
            if(node==null){
                break;
            }
        }
        System.out.println();
    }

    public void add(Node node){
        Node next = this.next;
        this.next = node;
        node.next = next;
    }

    public void remove(){
        this.next = (this.next==null)?null:this.next.next;
    }

    public static void main(String[] args){
        Node node1 = new Node(9);
        Node node2 = new Node(8);
        Node node3 = new Node(7);
        node1.append(node2);
        node2.append(node3);
        node1.show();
        Node node4 = new Node(6);
        node2.add(node4);
        node1.show();
        node1.remove();
        node1.show();
    }
}